#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: liang kang
@contact: gangkanli1219@163.com
@desc: 
"""
import argparse

from dltools.data.dataset.cropper import VOCImageCropper
from dltools.utils.log import get_console_logger

from utils.file_read import GoodsReader


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--root', type=str, default='', dest='root',
        help='The directory where the image data and the annotation is stored.'
             '保存图像与标记数据的根目录, 图像与其相应标记应当在同一级目录。')
    parser.add_argument(
        '--output', type=str, default='', dest='output',
        help='the root for all the output.'
             '输出结果的根目录')
    parser.add_argument(
        '--height', type=int, default=960, dest='height',
        help='输出子图的高')
    parser.add_argument(
        '--width', type=int, default=960, dest='width',
        help='输出子图的宽')
    parser.add_argument(
        '--stride', type=int, default=180, dest='stride',
        help='输出子图的宽')
    return parser.parse_args()


if __name__ == '__main__':
    ARGS = parse_args()
    label_list = []
    for idx in range(30):
        label_list.append('package%d' % idx)
    logger = get_console_logger('DataCreator')
    reader = GoodsReader(ARGS.root, logger)
    for data in reader:
        cropper = VOCImageCropper(data['image'], data['xml'], ARGS.output,
                                  (ARGS.height, ARGS.width),
                                  (ARGS.stride, ARGS.stride),
                                  threshold=1.0, label_list=label_list,
                                  logger=logger)
        cropper.update()
